<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>权限管理</title>
<meta name="layout" content="common_header"/>

<link rel="stylesheet" type="text/css" href="${resource(dir: 'jsTree', file: 'tree_component.css', absolute: true)}" />


<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'jquery.metadata.pack.js', absolute: true)}"></script>
<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'jquery.cookie.js', absolute: true)}"></script>
<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'ui.core.js', absolute: true)}"></script>


<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'common.custom.js', absolute: true)}"></script>
<script type="text/javascript" src="${resource(dir: 'jsTree', file: 'minified_lib.js', absolute: true)}"></script>
<script type="text/javascript" src="${resource(dir: 'jsTree', file: 'common_func.js', absolute: true)}"></script>

<script type="text/javascript" src="${resource(dir: 'jsTree', file: 'tree_component.min.js', absolute: true)}"></script>

<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'jquery.form.min.js', absolute: true)}"></script>
<script type="text/javascript" src="${resource(dir: 'js/jquery', file: 'jquery.blockUI.min.js', absolute: true)}"></script>










<script type="text/javascript">
  var permissionTree = jQuery.tree_create();
  jQuery(document).ready(function() {
    permissionTree.init(jQuery("#permission_tree"), {
      rules : { draggable : "none"},
      ui : {
        theme_name : "checkbox"
      },
      callback : {
        onchange:function(NODE, TREE_OBJ) {
          checkbox(NODE, TREE_OBJ);
        }
      }
    });
    initPermission();
  });
  function initPermission() {
    var permission = jQuery("#permission").val();
    for (var i = 0; i < permission.length; i++) {
      var ch = permission.charAt(i);
      var node = jQuery("#" + i);
      if ("1" == ch) {
        node.children("a").addClass("checked");
      } else if ("2" == ch) {
        node.children("a").addClass("undetermined");
      } else {
        node.children("a").addClass("unchecked");
      }
    }
  }
  function saveTree() {
    var permission = initArray(100, "0");
    permissionTree.container.find("a.checked,a.undetermined").each(
            function() {
              var node = jQuery(this);
              var index = node.parent().attr("id");
              if (node.hasClass("checked")) {
                permission[index] = "1";
              } else {
                permission[index] = "2";
              }
            });
    jQuery("#permission").val(arr2String(permission));
    jQuery.blockUI();
    jQuery("#submitForm").ajaxSubmit({
      success: function(response) {
        jQuery.unblockUI();
        alert("保存成功");
      }
    });
  }
  function initArray(length, defaultValue) {
    var arr = new Array(length);
    for (var i = 0; i < length; i++)arr[i] = defaultValue;
    return arr;
  }
  function arr2String(arr) {
    var str = "";
    for (var i = 0; i < arr.length; i++)str += arr[i];
    return str;
  }
</script>

</head>

<body>
<div class="man_zone">
  <table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" class="table_style">
    <tr>
      <td width="100%">
        <div><a id="doSave" href="javaScript:saveTree()"><img src="${resource(dir: '/images/admin_ui/', file: 'save1.gif', absolute: true)}" alt="保存" border=0/></a></div>
        <div><font id="sortNameArea" color="red">一般用户</font>的权限</div>
        <div id="permission_tree" style="text-align:left;height:400px">
          <ul>
            <li id="1"><a href="#">楼盘管理</a>
              <ul>
                <li id="11"><a href="#">楼盘管理</a></li>

              </ul>
            </li>
            <li id="2"><a href="#">信息管理</a>
              <ul>
                <li id="21"><a href="#">房源信息</a></li>
              </ul>
            </li>
            <li id="3"><a href="#">用户管理</a>
              <ul>
                <li id="31"><a href="#">用户管理</a></li>

              </ul>
            </li>

            <li id="4"><a href="#">链接管理</a>
              <ul>
                <li id="41"><a href="#">友情链接</a></li>

              </ul>
            </li>

            <li id="5"><a href="#">报表统计</a>
              <ul>
                <li id="51"><a href="#">用户竞标数量统计</a></li>

              </ul>
            </li>


            <li id="6"><a href="#">系统管理</a>
              <ul>
                <li id="61"><a href="#">环境变量设置</a></li>
                <li id="62"><a href="#">系统用户管理</a></li>
                <li id="63"><a href="#">角色管理</a></li>
                <li id="64"><a href="#">管理员日志</a></li>

              </ul>
            </li>
            <li id="7"><a href="#">消息管理</a>
              <ul>
                <li id="71"><a href="#">消息管理</a></li>

              </ul>
            </li>

          </ul>
        </div>
      </td>
    </tr>
  </table>
</div>
<form id="submitForm" name="submitForm" action="${createLink(controller: "scaffold", action: 'save', absolute: true)}" method="post">
  <input type="hidden" name="property" value="${bo?.class.simpleName}"/>
  <input type="hidden" name="id" value="${bo?.id}">
  <input type="hidden" id="permission" name="permission" value="${bo?.permission}">
</form>
</body>